package com.review.reviewsb.mapper;

import com.review.reviewsb.domain.User;
import com.review.reviewsb.domain.Video;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.Mapping;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: reviewSb
 * @description: 用户模拟数据
 * @author: YaoZhiLi
 * @create: 2021-07-03 08:48
 */

@Repository
public class UserMapper {
    private static Map<String, User> userMap = new HashMap<>();

    static {
        userMap.put("root", new User(1, "root", "root"));
        userMap.put("admin", new User(2, "admin", "admin"));
        userMap.put("test", new User(3, "test", "test"));
    }

    public User login(String name, String pwd) {
        User user = userMap.get(name);
        if (user == null) {
            return null;
        }
        if (user.getPwd().equals(pwd)) {
            return user;
        }
        return null;
    }

    public List userList(){
        List<User> userList = new ArrayList<>();
        userList.addAll(userMap.values());
        return userList;
    }
}
